Completed
Push — master ( 7403a2...9afade )
by Taavo-Taur
02:16
created

feathers-server.js ➔ ???   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 30
rs 8.8571
1
import feathers from 'feathers'
2
import feathersClient from 'feathers/client'
3
import feathersSocketIOclient from 'feathers-socketio/client'
4
import localSocketer from './feathers-socket'
5
import {SocketIO} from './mock-socket'
6
7
function localClient(url) {
8
	const connection = new SocketIO(url)
9
	// fool feathers into thinking it's socketio
10
	connection.io = true
11
12
	return feathersSocketIOclient(connection)
13
}
14
15
let instance = 8901
16
17
export default function () {
18
	const server = feathers()
19
	const url = 'http://localtest:' + instance++
20
21
	server.configure(localSocketer(url))
22
23
	// Services can be bound late
24
25
	// Manually call server setup method
26
	server.setup()
27
28
	return {
29
		server,
30
		getClient: (awaiting = true) => {
31
			const client = feathersClient().configure(localClient(url))
32
			if (awaiting) {
33
				return new Promise((resolve, reject) => {
34
					client.io.on('connect', () => {
35
						resolve(client)
36
					})
37
					client.io.on('close', error => {
38
						reject(error)
39
					})
40
				})
41
			}
42
43
			return client
44
		}
45
	}
46
}
47